package com.dongdongshop.controller;

import com.dongdongshop.enums.ResultEnum;
import com.dongdongshop.pojo.TbSeller;
import com.dongdongshop.service.SellerService;
import com.dongdongshop.util.Result;
import com.dongdongshop.util.ShiroUtils;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.Date;

@Controller
@RequestMapping("seller")
public class SellerController {

    @DubboReference
    private SellerService ss;


    @RequestMapping("show")
    public String show(){
        return "register";
    }


    @RequestMapping("register")
    @ResponseBody
    public Result register(TbSeller seller){
        try {
            ShiroUtils shiroUtils = new ShiroUtils();
            //使用加盐的方法获取一个新值
            String s = shiroUtils.saltPassword(seller.getPassword());
            //截取
            String[] split = s.split(",");
            //给审核默认为0
            seller.setStatus("0");
            seller.setPassword(split[1]);
            seller.setSalt(split[0]);
            seller.setCreateTime(new Date());
            ss.insertSeller(seller);
            return Result.response(ResultEnum.ENROLL_SUCCESS);
        } catch (Exception e) {
            return Result.response(ResultEnum.ENROLL_ERROR);
        }
    }

}
